﻿Imports Microsoft.Reporting.WinForms

Public Class frmInPhieuXuatNhap
    Public nhapxuat As Boolean
    Public rpName As String
    Public dsName As String

    Private vwpn As vwChiTietPhieuNhap
    Private vwpx As vwChiTietPhieuXuat

    Private _PhieuNhap As tbPhieuNhap
    Property PhieuNhap As tbPhieuNhap
        Get
            Return _PhieuNhap
        End Get
        Set(value As tbPhieuNhap)
            _PhieuNhap = value
            vwpn = (From hd In dt.vwChiTietPhieuNhaps
                    Where hd.id = value.id
                    Select hd).First
        End Set
    End Property

    Private _PhieuXuat As tbPhieuXuat
    Property PhieuXuat As tbPhieuXuat
        Get
            Return _PhieuXuat
        End Get
        Set(value As tbPhieuXuat)
            _PhieuXuat = value
            vwpx = (From hd In dt.vwChiTietPhieuXuats
                    Where hd.id = value.id
                    Select hd).First
        End Set
    End Property

    Private Sub frmInXuatNhap_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.ReportViewer1.LocalReport.ReportPath = rpName
        'Me.ClientSize = New System.Drawing.Size(700, 600)

        ReportViewer1.LocalReport.EnableExternalImages = True
        Dim rls
        If nhapxuat Then
            rls = dt.vwChiTietPhieuNhaps.Where(Function(s) s.id = PhieuNhap.id)
        Else
            rls = dt.vwChiTietPhieuXuats.Where(Function(s) s.id = PhieuXuat.id)
        End If
        Dim bs As New BindingSource
        bs.DataSource = rls
        Dim ds As New ReportDataSource
        ds.Name = dsName
        ds.Value = bs
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(ds)
        ReportViewer1.LocalReport.SetParameters(DanhSachThamSo(vwpn, vwpx, nhapxuat))
        ReportViewer1.RefreshReport()
    End Sub

End Class